package cn.jbolt.core.permission;
/**
 * 用户权限工具类
* @author 小木
*/

import cn.jbolt.core.service.JBoltRolePermissionService;
import cn.jbolt.core.service.JBoltUserService;
import cn.jbolt.core.util.JBoltArrayUtil;
import com.jfinal.aop.Aop;

public class JBoltUserAuthKit {
	private static JBoltUserService userService = Aop.get(JBoltUserService.class);
	private static JBoltRolePermissionService rolePermissionService = Aop.get(JBoltRolePermissionService.class);

	/**
	 * 判断用户是否有指定所有角色
	 *
	 * @param userId
	 * @param checkAll
	 * @param roleIds
	 * @return
	 */
	public static boolean hasRole(Long userId, boolean checkAll, Long... roleIds) {
		return userService.checkUserHasRole(userId, checkAll, roleIds);
	}

	/**
	 * 判断用户是否有指定所有角色
	 *
	 * @param userId
	 * @param checkAll
	 * @param roleIdStr
	 * @return
	 */
	public static boolean hasRole(Long userId, boolean checkAll, String roleIdStr) {
		return hasRole(userId, checkAll, JBoltArrayUtil.toDisLong(roleIdStr));
	}


	/**
	 * 判断用户是否有指定所有角色 用sn
	 *
	 * @param userId
	 * @param checkAll
	 * @param roleSns
	 * @return
	 */
	public static boolean hasRoleSn(Long userId, boolean checkAll, String... roleSns) {
		return userService.checkUserHasRoleSn(userId, checkAll, roleSns);
	}

	/**
	 * 判断用户是否有指定所有角色
	 *
	 * @param userId
	 * @param roleIds
	 * @return
	 */
	public static boolean hasRole(Long userId, Long... roleIds) {
		return hasRole(userId, false, roleIds);
	}

	/**
	 * 判断用户是否有指定所有角色
	 *
	 * @param userId
	 * @param roleIdStr
	 * @return
	 */
	public static boolean hasRole(Long userId, String roleIdStr) {
		return hasRole(userId, false, roleIdStr);
	}

	/**
	 * 判断用户是否有指定所有角色 用sn
	 *
	 * @param userId
	 * @param roleSns
	 * @return
	 */
	public static boolean hasRoleSn(Long userId, String... roleSns) {
		return hasRoleSn(userId, false, roleSns);
	}

	/**
	 * 判断用户是否有指定权限
	 *
	 * @param userId
	 * @param checkAll
	 * @param permissionKeys
	 * @return
	 */
	public static boolean hasPermission(Long userId, boolean checkAll, String... permissionKeys) {
		return rolePermissionService.checkUserHasPermission(userId, checkAll, permissionKeys);
	}

	/**
	 * 判断用户是否有指定权限
	 *
	 * @param userId
	 * @param permissionKeys
	 * @return
	 */
	public static boolean hasPermission(Long userId, String... permissionKeys) {
		return hasPermission(userId, false, permissionKeys);
	}

}
